<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:replace="include/head::head"></head>

<body class="nav-md">
<div class="container body">
    <div class="main_container">

        <div th:replace="/include/sidebar"></div>
        <!-- top navigation -->
        <div th:replace="include/navigation::navigation"></div>
        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 ">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>试题更改 <small></small></h2>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <br />
                                <form id="single-upload" data-parsley-validate class="form-horizontal form-label-left" action="" method="post" onsubmit="return false">

                                    <div class="item form-group">
                                        <label class="col-form-label col-md-3 col-sm-3 label-align" for="section">所属章节 <span class="required"></span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <select class="form-control" id="section">
                                                <option th:each="section,sectionstate:${sections}" th:value="${section.secId}" th:text="${section.secName}" th:selected="${section.secId==question.quesSection}"></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="col-form-label col-md-3 col-sm-3 label-align" for="type">试题类型 <span class="required"></span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <select class="form-control" id="type">
                                                <option th:each="type,typestate:${types}" th:value="${type.dicId}" th:text="${type.dicValue}" th:selected="${type.dicId==question.quesType}">Choose option</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label for="level" class="col-form-label col-md-3 col-sm-3 label-align">试题难度</label>
                                        <div class="col-md-6 col-sm-6 ">
                                            <select class="form-control" id="level">
                                                <option th:each="level,levelstate:${levels}" th:value="${level.dicId}" th:text="${level.dicValue}" th:selected="${level.dicId==question.quesLevel}">Choose option</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label for="content" class="col-form-label col-md-3 col-sm-3 label-align">试题内容</label>
                                        <div class="col-md-7 col-sm-6 ">
                                            <div id="content" class="editor-wrapper placeholderText" contenteditable="true" style="min-height: 120px;" th:text="${question.quesContent}"></div>
                                            <textarea id="contents" name="descr"  style="display:none;"></textarea>
                                            <br>

                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label for="answer" class="col-form-label col-md-3 col-sm-3 label-align">试题答案</label>
                                        <div class="col-md-7 col-sm-6 ">
                                            <div id="answer" class="editor-wrapper placeholderText" contenteditable="true" style="min-height: 100px;" th:text="${question.quesAnswer}"></div>
                                            <textarea name="descr"  style="display:none;"></textarea>
                                            <br>

                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label for="describe" class="col-form-label col-md-3 col-sm-3 label-align">试题解析</label>
                                        <div class="col-md-7 col-sm-6 ">
                                            <div id="describe" class="editor-wrapper placeholderText" contenteditable="true" style="min-height: 120px;" th:text="${question.quesDescribe}"></div>
                                            <textarea name="descr" style="display:none;"></textarea>
                                            <br>

                                        </div>
                                    </div>
                                    <div class="actionBar">
                                        <a href="#" class="buttonFinish btn btn-default">返回题库</a>
                                        <a href="#" class="buttonFinish btn btn-default">提交申请</a>
                                        <a href="#" class="buttonNext btn btn-success">下一道题</a>
                                        <a href="#" class="buttonPrevious btn btn-primary ">上一道题</a>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- /page content -->


        <!-- footer content -->
        <div th:replace="include/footer::footer">
            <!-- /footer content -->
        </div>
    </div>
</div>
<div id="custom_notifications" class="custom-notifications dsp_none">
    <ul class="list-unstyled notifications clearfix" data-tabbed_notifications="notif-group">
    </ul>
    <div class="clearfix"></div>
    <div id="notif-group" class="tabbed_notifications"></div>
</div>

<div th:replace="include/javascript::javascript"></div>
<!--pagescript-->
<script>
    $(function () {
        $("#reset-question").on("click",function () {
            $("#content").text(" ");
            $("#answer").text(" ");
            $("#describe").text(" ");
        })
        $("#submit-question").on("click",function () {
            var section=$("#section").find("option:selected").val();
            var type=$("#type").find("option:selected").val();
            var level=$("#level").find("option:selected").val();
            var content=$("#content").text();
            var answer=$("#answer").text();
            var describe=$("#describe").text();
            $.ajax({
                type:"post",
                url:"/question/single_upload",
                data:{section:section,type:type,level:level,content:content,answer:answer,describe:describe},
                dataType:"json",
                success:function (message) {
                    if (message.success){
                        alert("上传成功");
                    }
                }
            });
        });
        $("#submit-file").on("click",function () {
            var file=$("#file")[0].files[0];
            var formData = new FormData();
            formData.append("file",file);
            $.ajax({
                type : "post",
                url : "/question/file_upload",
                data : formData,
                processData : false,
                contentType : false,
                cache:false,
                success : function(message){
                    if (message.success){
                        alert("上传成功");
                    }
                }
            });
        });
    })
</script>
</body>
</html>